﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace BACKOFFICE
{
    public partial class EmployeePayrollScreen : DevExpress.XtraEditors.XtraUserControl
    {
        Dictionary<int, string> Employees = new Dictionary<int, string>();
        TimeSpan Wk1TotalTime;
        TimeSpan Wk2TotalTime;
        TimeSpan Duration;
        string myConnectionString = DataTableClass.myConnectionString;

        public EmployeePayrollScreen()
        {
            InitializeComponent();

            //Console.Write(DateTime.Now.ToString());
            LoadEmployeeNames();
        }

        private void LoadEmployeeNames()
        {
            foreach (DataRow item in DataTableClass.EmployeeInfo.Rows)
            {
                comboBoxEdit1.Properties.Items.Add(item["EmployeeFirstName"].ToString().Trim() + " " + item["EmployeeLastName"].ToString().Trim());
                Employees.Add((int)(item["EmployeeID"]), item["EmployeeFirstName"].ToString().Trim() + " " + item["EmployeeLastName"].ToString().Trim());
            }
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (KeyValuePair<int, string> EMPLOYEES in Employees)
            {
                if (EMPLOYEES.Value.ToString() == comboBoxEdit1.EditValue.ToString())
                {
                    lblEmployeeID.Text = EMPLOYEES.Key.ToString();

                    foreach (DataRow row in DataTableClass.EmployeeInfo.Rows)
                    {
                        if (row["EmployeeID"].ToString().Trim() == lblEmployeeID.Text)
                        {
                            lblPayRate.Text = row["EmployeePayRate"].ToString().Trim();
                        }
                    }
                }
            }

            GetEmployeesTimeSheetRecords(Convert.ToInt32(lblEmployeeID.Text));
        }

        private void GetEmployeesTimeSheetRecords(int EmpID)
        {
            Wk1TotalTime = TimeSpan.Zero;
            Wk2TotalTime = TimeSpan.Zero;

            List<TextEdit> TimesheetBoxes = new List<TextEdit> { MondayWk1A,MondayWk1B,TuesdayWk1A,TuesdayWk1B,WednesdayWk1A,WednesdayWk1B,ThursdayWk1A,
                                                                 ThursdayWk1B,FridayWk1A,FridayWk1B,SaturdayWk1A,SaturdayWk1B,SundayWk1A,SundayWk1B,

                                                                 MondayWk2A,MondayWk2B,TuesdayWk2A,TuesdayWk2B,WednesdayWk2A,WednesdayWk2B,
                                                                 ThursdayWk2A,ThursdayWk2B,FridayWk2A,FridayWk2B,SaturdayWk2A,SaturdayWk2B,SundayWk2A,SundayWk2B};

            foreach (TextEdit item in TimesheetBoxes)
            {
                item.Text = "";
            }

            if (dateEdit1.SelectedText.ToString() == "")// || dateEdit2.SelectedText.ToString() == "")
            {
                MessageBox.Show("Please Enter Payroll Period");
            }
            else
            {
                foreach (DataRow item in DataTableClass.EmployeeTimeSheet.Rows)
                {
                    if (item["EmployeeID"].ToString().Trim() == EmpID.ToString())
                    {
                        if ((Convert.ToDateTime(item["Date"]) >= Convert.ToDateTime(dateEdit1.Text)) && (Convert.ToDateTime(item["Date"]) <= Convert.ToDateTime(dateEdit1.Text).AddDays(13)))
                        {
                            DateTime date = Convert.ToDateTime(item["Date"].ToString().Trim());
                            DateTime ClockInTime = Convert.ToDateTime(item["ClockIN"].ToString().Trim());
                            DateTime ClockOutTime = Convert.ToDateTime(item["ClockOUT"].ToString().Trim());
                            DateTime SecondWeek = Convert.ToDateTime(dateEdit1.Text).AddDays(6);
                            string EntID = item["EntryID"].ToString().Trim();

                            if (date <= SecondWeek)
                            {
                                switch (date.ToString("dddd").ToUpper())
                                {
                                    case "MONDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                MondayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                MondayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                MondayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                MondayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                        }
                                        break;

                                    case "TUESDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                TuesdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                TuesdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk1A.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                TuesdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                TuesdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "WEDNESDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                WednesdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                WednesdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk1A.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                WednesdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                WednesdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "THURSDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                ThursdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                ThursdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk1A.Text);
                                                Wk1TotalTime += Duration;

                                            }

                                        }
                                        else
                                        {
                                            try
                                            {
                                                ThursdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                ThursdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "FRIDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                FridayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                FridayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk1A.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                FridayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                FridayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "SATURDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                SaturdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SaturdayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk1A.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                SaturdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SaturdayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "SUNDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                SundayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk1A.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SundayWk1A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk1A.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                SundayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk1B.Text);
                                                Wk1TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SundayWk1B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk1B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                        }
                                        break;
                                }
                            }
                            else if (date > SecondWeek)
                            {
                                switch (date.ToString("dddd").ToUpper())
                                {
                                    case "MONDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                MondayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                MondayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                MondayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk2B.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                MondayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(MondayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;
                                    case "TUESDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                TuesdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                TuesdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                TuesdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk2B.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                TuesdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(TuesdayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "WEDNESDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                WednesdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);


                                                WednesdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                WednesdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk2B.Text);
                                                Wk1TotalTime += Duration;

                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                WednesdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(WednesdayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "THURSDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                ThursdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                ThursdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }

                                        }
                                        else
                                        {
                                            try
                                            {
                                                ThursdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk2B.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                ThursdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(ThursdayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "FRIDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                FridayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                FridayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                FridayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk2B.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                FridayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(FridayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "SATURDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                SaturdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SaturdayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                SaturdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk2B.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SaturdayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SaturdayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;

                                    case "SUNDAY":
                                        if (ClockInTime.TimeOfDay < new TimeSpan(14, 30, 00))
                                        {
                                            try
                                            {
                                                SundayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk2A.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SundayWk2A.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk2A.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        else
                                        {
                                            try
                                            {
                                                SundayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk2B.Text);
                                                Wk2TotalTime += Duration;
                                            }
                                            catch
                                            {
                                                UpdateRecords(EntID, ClockInTime, ClockOutTime);

                                                SundayWk2B.Text = item["HoursTotal"].ToString().Trim();
                                                Duration = TimeSpan.Parse(SundayWk2B.Text);
                                                Wk2TotalTime += Duration;

                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }

            txtWeek1Total.Text = Wk1TotalTime.TotalHours.ToString();
            txtWeek2Total.Text = Wk2TotalTime.TotalHours.ToString();
        }

        private void UpdateRecords(string EntryID, DateTime ClockIn, DateTime ClockOut)
        {
            DataRow[] UPDATE = DataTableClass.EmployeeTimeSheet.Select("EntryID =" + EntryID);
            TimeSpan duration2 = DateTime.Parse(ClockOut.ToLongTimeString()).Subtract(DateTime.Parse(ClockIn.ToLongTimeString()));
            UPDATE[0]["HoursTotal"] = duration2.ToString();
        }

        private void CalculateCheck()
        {
            txtMiscWk1.Text = "";
            txtMiscWk2.Text = "";

            double PayRate = Convert.ToDouble("8.60");
            double OtPayRate = PayRate * 1.5;

            double HrsWk1 = 80;// Wk1TotalTime.TotalHours;
            double HrsWk2 = 19;// Wk1TotalTime.TotalHours;
            double TotalHours = HrsWk1 + HrsWk2;

            double TotalRegHours;
            double TotalOtHours;

            double TotalAmountRegHours;
            double TotalAmountOtHours;

            double GrossPay;
            double FedDeductionAmount;

            double SSdeductionPercentage = 0.062;
            double SSdeductionAmount;

            double MedDeductionPercentage = 0.0145;
            double MedDeductionAmount;

            double Wk1Tips = Convert.ToDouble(textEdit6.Text);
            double Wk2Tips = Convert.ToDouble(textEdit5.Text);

            double NetPay;

            if (TotalHours > 80)
            {
                TotalRegHours = 80;
                TotalOtHours = TotalHours - 80;
            }
            else 
            {
                TotalRegHours = TotalHours;
                TotalOtHours = 0;
            }

            TotalRegHours = Math.Round(TotalRegHours, 2);// Math.Round(TotalRegHours, 2);
            TotalOtHours = Math.Round(TotalOtHours, 2);// Math.Round(TotalOtHours, 2);
            txtRegHrs.Text = TotalRegHours.ToString();
            txtOtHrs.Text = TotalOtHours.ToString();

            TotalAmountRegHours = TotalRegHours * PayRate;
            TotalAmountOtHours = TotalOtHours * OtPayRate;
            TxtRegAmount.Text = TotalAmountRegHours.ToString("C");
            TxtOtAmount.Text = TotalAmountOtHours.ToString("C");

            GrossPay = TotalAmountRegHours + TotalAmountOtHours;// +Wk1Tips + Wk2Tips;

            double wk1Calculation = (TotalAmountRegHours + TotalAmountOtHours + Wk1Tips) / (TotalRegHours + TotalOtHours);

            if (wk1Calculation < 7.25)
            {
                double NeedsToEqual = (TotalRegHours + TotalOtHours) * 7.25;
                double CurrentSum = (TotalAmountRegHours + TotalAmountOtHours + Wk1Tips);

                txtMiscWk1.Text = Math.Round((NeedsToEqual - CurrentSum), 2).ToString();
                GrossPay += (NeedsToEqual - CurrentSum);

            }

            txtGrossEarnings.Text = GrossPay.ToString("C");

            FedDeductionAmount = FedTaxTabelClass.Bracket1(1, GrossPay);
            txtfeddeductamount.Text = FedDeductionAmount.ToString("C");

            SSdeductionAmount = GrossPay * SSdeductionPercentage;
            txtssdeductamount.Text = SSdeductionAmount.ToString("C");

            MedDeductionAmount = GrossPay * MedDeductionPercentage;
            txtmeddeductamount.Text = MedDeductionAmount.ToString("C");

            txtTotalDeduct.Text = (FedDeductionAmount + SSdeductionAmount + MedDeductionAmount).ToString();

            NetPay = GrossPay - FedDeductionAmount - SSdeductionAmount - MedDeductionAmount;
            txtNetEarnings.Text = NetPay.ToString("C");


        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            CalculateCheck();
        }
    }
}
